from django.db import models
from bookDisplay.models import books


# Create your models here.
class User(models.Model):
    username = models.CharField(max_length=50, help_text=u"用户名")
    nickname = models.CharField(max_length=50, help_text=u"昵称")
    password = models.CharField(max_length=100, help_text=u"密码")
    avatar = models.ImageField(upload_to='avatars', help_text=u"头像")
    phone = models.CharField(max_length=11, help_text=u"手机号")
    email = models.EmailField(help_text=u"邮箱")
    create_time = models.DateTimeField(auto_now_add=True, help_text=u"创建时间")
    level = models.IntegerField(default=1, help_text=u"用户等级")


class Favorite(models.Model):
    user = models.ForeignKey(User, on_delete=models.CASCADE, help_text=u"用户", db_index=True)
    book = models.ForeignKey(books, on_delete=models.CASCADE, help_text=u"书籍", db_index=True)
    create_time = models.DateTimeField(auto_now_add=True, help_text=u"创建时间")
    font_size = models.IntegerField(default=16, help_text=u"字体大小")
    chapter_number = models.IntegerField(default=1, help_text=u"阅读章节")  # 用户离开这本书时，记录那一章
    page_number = models.IntegerField(default=1, help_text=u"阅读页码")  # 用户离开这本书时，记录那一页

    class Meta:
        unique_together = ('user', 'book')  # 确保用户不能重复收藏同一本书

